How to define function in javascript